<template>
  <div class="dao-intro">
    <el-row justify="center">
      <el-col :span="24">
        <h1>DAO 社区平台介绍</h1>
      </el-col>
    </el-row>
    

    <div class="content-container">
      <el-row :gutter="20">
        <el-col :span="9">
          <section class="intro-section">
            <h2>平台介绍</h2>
            <div class="intro-content">
              <div class="logo-container">
                <img src="../assets/images/logo.png" alt="DAO Logo" class="logo-image">
              </div>
              
              <h3>欢迎来到DAO社区平台</h3>
              <p class="welcome-text">欢迎来到前沿的去中心化自治组织 (DAO) 社区平台！我们为志同道合的个人提供了一个创新空间，旨在通过区块链技术的力量，共同构建、治理和发展基于Web3的项目。</p>
              
              <el-divider content-position="left">目标</el-divider>
              <p>我们致力于构建一个社区驱动、透明、公平、可持续的世界。</p>
              
              <el-divider content-position="left">路径</el-divider>
              <p>基于区块链的平台架构保障了决策过程的公开透明与不可篡改。通过去中心化的自治组织（DAO），社区成员共同制定和执行规则。</p>
            
              <div class="highlight-box">
                <p class="highlight-text">区块链服务不仅仅是技术创新，更是数据权利公有化、社会制度合约化的实践。</p>
              </div>
            </div>
            
          </section>
        </el-col>

        <el-col :span="9">
          <section class="tech-section">
            <h2>技术架构</h2>
            <div class="blockchain-compare">
              <div class="card-header">
                <span>BlockDAO - 区块链DAO社区框架</span>
                <small>区块链服务架构示例</small>
              </div>
              <el-table size="small" :data="tableData" :span-method="objectSpanMethod" border style="width: 100%">
                <el-table-column prop="module" label="模块" width="100" />
                <el-table-column prop="subModule" label="子模块" width="120" />
                <el-table-column prop="traditional" label="传统服务架构" />
                <el-table-column prop="blockchain" label="区块链服务架构" />
              </el-table>
            </div>
          </section>
        </el-col>

        <el-col :span="6">
          <section class="quick-start-section">
            <h2>快速开始</h2>
            
            <div class="animation-container">
              <div class="animation-scene">
                <div class="traditional-scene" v-show="currentScene === 'traditional'">
                  <div class="node client">
                    <el-icon><Monitor /></el-icon>
                    <span>客户端</span>
                  </div>
                  
                  <div class="arrow-group">
                    <el-icon><ArrowLeft /></el-icon>
                    <el-icon><ArrowRight /></el-icon>
                  </div>

                  <div class="server-group">
                    <div class="node server">
                      <el-icon><MostlyCloudy /></el-icon>
                      <span>服务器</span>
                    </div>
                    <div class="node cdn">
                      <el-icon><Connection /></el-icon>
                      <span>CDN</span>
                    </div>
                  </div>
                </div>
                
                <div class="blockchain-scene" v-show="currentScene === 'blockchain'">
                  <div class="node client-with-key">
                    <el-icon><Key /></el-icon>
                    <span>客户端</span>
                  </div>

                  <div class="arrow-group">
                    <el-icon><ArrowLeft /></el-icon>
                    <el-icon><ArrowRight /></el-icon>
                  </div>

                  <div class="nodes-group">
                    <div class="blockchain-nodes">
                      <div class="node">
                        <el-icon><Share /></el-icon>
                        <span>区块链节点</span>
                      </div>
                      <div class="node">
                        <el-icon><Share /></el-icon>
                        <span>区块链节点</span>
                      </div>
                    </div>
                    <div class="ipfs-nodes">
                      <div class="node">
                        <el-icon><Files /></el-icon>
                        <span>IPFS节点</span>
                      </div>
                      <div class="node">
                        <el-icon><Files /></el-icon>
                        <span>IPFS节点</span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              
              <el-button-group class="scene-switcher">
                <el-button 
                  :type="currentScene === 'traditional' ? 'primary' : 'default'"
                  @click="handleManualSwitch('traditional')">
                  传统架构
                </el-button>
                <el-button 
                  :type="currentScene === 'blockchain' ? 'primary' : 'default'"
                  @click="handleManualSwitch('blockchain')">
                  区块链架构
                </el-button>
              </el-button-group>
            </div>

            <div class="steps-section">
              <el-steps direction="vertical" :active="3" finish-status="success">
                <el-step title="创建密钥" description="下载密钥管理器创建自己的密钥" />
                <el-step title="连接平台" description="访问平台应用，连接密钥管理器" />
                <el-step title="开始参与" description="加入社区讨论，参与投票" />
              </el-steps>
              
              <el-alert
                class="join-alert"
                type="success"
                :closable="false"
                show-icon>
                <p class="call-to-action">立即加入，共创Web3新纪元！</p>
              </el-alert>
            </div>
          </section>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { Monitor, MostlyCloudy, Connection, Key, Share, Files, ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import { ref, onMounted, onUnmounted } from 'vue'

interface TableItem {
  module: string
  subModule: string
  traditional: string
  blockchain: string
}

const tableData: TableItem[] = [
  {
    module: '服务端',
    subModule: '数据中心',
    traditional: '私有云',
    blockchain: '公有云'
  },
  {
    module: '服务端',
    subModule: '服务稳定性',
    traditional: '依靠私有公司',
    blockchain: '依靠公共社区'
  },
  {
    module: '服务端',
    subModule: '数据备份',
    traditional: '额外部署备份',
    blockchain: '节点互为备份'
  },
  {
    module: '服务端',
    subModule: '数据冗余',
    traditional: '每个公司一份数据',
    blockchain: '全社会只有一份数据'
  },
  {
    module: '服务端',
    subModule: '可升级性',
    traditional: '单一架构',
    blockchain: '不同节点可不同架构'
  },
  {
    module: '客户端',
    subModule: '用户账户',
    traditional: '每个服务一套',
    blockchain: '使用密钥作为账号'
  },
  {
    module: '客户端',
    subModule: '隐私安全',
    traditional: '需要保存隐私数据',
    blockchain: '隐私数据集中保管，非必要不使用'
  },
  {
    module: '客户端',
    subModule: '日志记录',
    traditional: '逐一埋点',
    blockchain: '所有交易都有记录'
  },
  {
    module: '客户端',
    subModule: '开发难度',
    traditional: '难，需要前后端开发',
    blockchain: '易，只需要开发前端，后台由区块链提供'
  },
  {
    module: '社会价值',
    subModule: '数据所有权',
    traditional: '私营公司',
    blockchain: '社会共有'
  },
  {
    module: '社会价值',
    subModule: '规则制定',
    traditional: '私营公司制定规则',
    blockchain: '社会共识产生规则'
  },
  {
    module: '社会价值',
    subModule: '数据价值',
    traditional: '单一公司使用',
    blockchain: '按照共识协议公平提供数据'
  }
]

interface SpanMethodProps {
  rowIndex: number
  columnIndex: number
}

const objectSpanMethod = ({
  rowIndex,
  columnIndex,
}: SpanMethodProps) => {
  if (columnIndex === 0) {
    if (rowIndex === 0) {
      return {
        rowspan: 5,
        colspan: 1
      }
    } else if (rowIndex === 5) {
      return {
        rowspan: 4,
        colspan: 1
      }
    } else if (rowIndex === 9) {
      return {
        rowspan: 3,
        colspan: 1
      }
    } else {
      return {
        rowspan: 0,
        colspan: 0
      }
    }
  }
}

const currentScene = ref('traditional')
let timer: ReturnType<typeof setInterval> | null = null

// 切换场景函数
const switchScene = (scene: string) => {
  currentScene.value = scene
}

// 自动切换场景
const startAutoSwitch = () => {
  timer = setInterval(() => {
    currentScene.value = currentScene.value === 'traditional' ? 'blockchain' : 'traditional'
  }, 5000) // 每5秒切换一次
}

// 停止自动切换
const stopAutoSwitch = () => {
  if (timer) {
    clearInterval(timer)
    timer = null
  }
}

// 组件挂载时启动自动切换
onMounted(() => {
  startAutoSwitch()
})

// 组件卸载时清理定时器
onUnmounted(() => {
  stopAutoSwitch()
})

// 点击按钮手动切换时，重置定时器
const handleManualSwitch = (scene: string) => {
  switchScene(scene)
  stopAutoSwitch()
  startAutoSwitch()
}
</script>

<style scoped>
.dao-intro {
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}

.content-container {
  margin-top: 20px;
}

h1 {
  text-align: center;
  color: var(--el-color-primary);
  margin-top: 0px;
  margin-bottom: 20px;
  font-size: 1.8em;
}

h2 {
  color: var(--el-color-primary);
  margin-bottom: 20px;
  font-size: 1.5em;
}

h3 {
  color: var(--el-text-color-primary);
  margin-bottom: 15px;
  font-size: 1.3em;
}

.welcome-text {
  font-size: 1em;
  line-height: 1.6;
  color: var(--el-text-color-regular);
}

.intro-section, .tech-section, .quick-start-section {
  background: var(--el-bg-color);
  padding: 20px;
  border-radius: var(--el-border-radius-base);
  box-shadow: var(--el-box-shadow-light);
  height: calc(100% - 60px);
}

.intro-content {
  height: 100%;
}

.steps-section {
  margin-top: 30px;
  padding: 10px;
  background-color: var(--el-fill-color-lighter);
  border-radius: var(--el-border-radius-base);
}

.join-alert {
  margin-top: 20px;
}

.call-to-action {
  color: var(--el-color-success);
  font-weight: bold;
  text-align: center;
  margin: 10px 0;
  font-size: 0.9em;
}

.card-header {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}

.card-header small {
  color: var(--el-text-color-secondary);
  font-size: 0.9em;
}

.highlight-box {
  margin-top: 30px;
  padding: 10px;
  background: var(--el-color-success-light-9);
  border-radius: var(--el-border-radius-base);
  border-left: 5px solid var(--el-color-success);
}

.highlight-text {
  font-size: 1.1em;
  line-height: 1.8;
  color: var(--el-text-color-primary);
  text-align: center;
  font-weight: 500;
  margin: 0;
}

.logo-container {
  text-align: center;
  margin: 0 0 20px 0;
}

.logo-image {
  max-width: 90px;
  height: auto;
}

.cell-with-rowspan {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--el-text-color-primary);
}

.sub-module {
  font-weight: 500;
  color: var(--el-text-color-regular);
}

.cell-content {
  display: block;
  line-height: 1.5;
  padding: 5px 0;
}

.el-table {
  margin-bottom: 20px;
  --el-table-border-color: var(--el-border-color);
  --el-table-header-bg-color: var(--el-fill-color-light);
}

.el-table th {
  background-color: var(--el-fill-color-light);
  font-weight: bold;
}

.el-table .cell {
  white-space: normal;
  line-height: 1.5;
}

:deep(.el-table__cell) {
  padding: 8px 0;
}

:deep(.el-table--striped .el-table__body tr.el-table__row--striped td) {
  background-color: var(--el-table-row-hover-bg-color);
}

@media (max-width: 1200px) {
  .dao-intro {
    padding: 10px;
  }
  
  .el-col {
    width: 100% !important;
    margin-bottom: 20px;
  }
}

@media (max-width: 768px) {
  .dao-intro {
    padding: 10px;
  }
  
  .el-col {
    width: 100% !important;
  }
  
  .intro-content {
    margin-bottom: 20px;
  }
  
  .el-table {
    font-size: 12px;
  }
}

.animation-container {
  border-radius: var(--el-border-radius-base);
}

.animation-scene {
  height: 200px;
  position: relative;
  margin-bottom: 15px;
  background: var(--el-bg-color);
  border-radius: var(--el-border-radius-base);
  overflow: hidden;
  padding: 20px;
}

.traditional-scene {
  height: 100%;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.server-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.blockchain-scene {
  height: 100%;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nodes-group {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.blockchain-nodes, .ipfs-nodes {
  display: flex;
  gap: 20px;
}

.node {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  border-radius: 8px;
  background: var(--el-bg-color);
  box-shadow: var(--el-box-shadow-light);
  transition: all 0.3s ease;
  width: 40px;
}

.node:hover {
  transform: scale(1.05);
  box-shadow: var(--el-box-shadow);
}

.node span {
  margin-top: 8px;
  font-size: 12px;
  color: var(--el-text-color-secondary);
}

.node .el-icon {
  font-size: 24px;
  color: var(--el-color-primary);
}

.blockchain-nodes .node,
.ipfs-nodes .node {
  animation: nodeFloat 3s infinite;
}

.blockchain-nodes .node:nth-child(2) {
  animation-delay: 0.5s;
}

.ipfs-nodes .node:nth-child(2) {
  animation-delay: 0.7s;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes nodeFloat {
  0% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
  100% { transform: translateY(0); }
}

.scene-switcher {
  display: flex;
  justify-content: center;
}

.arrow-group {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--el-color-primary);
  font-size: 20px;
}

.arrow-group .el-icon {
  animation: fadeInOut 2s infinite;
}

.arrow-group .el-icon:first-child {
  animation-delay: 1s;
}

@keyframes fadeInOut {
  0% { opacity: 0.3; }
  50% { opacity: 1; }
  100% { opacity: 0.3; }
}
</style>